/**
 * Copyright 2015-2016 eyaomall.cn
 * All rights reserved.
 *
 * @project
 * @author jackey
 * @version 1.0
 * @date 2016-01-06
 */
package com.eyaomall.wxmanage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eyaomall.wxmanage.common.error.BECode;
import com.eyaomall.wxmanage.model.po.Receipt;
import com.eyaomall.wxmanage.service.ReceiptService;
/**
 * 应收款单controller
 * @author pro
 *
 */
import com.lycheeframework.core.cmp.api.http.GsnData;
import com.lycheeframework.core.cmp.api.http.GsnResponse;
import com.lycheeframework.core.cmp.kit.PageHTTPObject;
import com.lycheeframework.core.cmp.kit.Pages;
import com.lycheeframework.core.exception.ErrorCodeException;
@Controller
@RequestMapping("receipt")
public class ReceiptController {

	@Autowired
	private ReceiptService receiptService;
	
	/**
	 * 应收款单首页
	 * @return
	 */
	@RequestMapping("index")
	public String index(){
		
		return "receipt/index";
	}
	
	/**
	 * 分页查询应收款单数据
	 * @param receipt
	 * @param httpObject
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("page")
	public @ResponseBody Pages<Receipt> page(Receipt receipt,PageHTTPObject httpObject){
		
		return (Pages<Receipt>) receiptService.page(receipt, httpObject);
	}
	
	/**
	 * 确认收款
	 * @param id
	 * @return
	 */
	@RequestMapping("receive")
	public @ResponseBody GsnData updateStatus(Integer id){
		if(id == null || id <= 0)
			throw new ErrorCodeException(BECode.receipt_4000001);
		
		Receipt receipt = new Receipt();
		receipt.setId(id);
		receipt.setStatus("1");
		
		return GsnResponse.toData(receiptService.update(receipt));
	}
}
